<!DOCTYPE html><!--STATUS OK-->
<html><head>
<meta http-equiv="X-UA-Compatible" content="IE=7">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>[var.out.mapsize] - ks random map [var.out.ver]</title>
<!-- <link href="[var.out.html_res_root]/res/table.css" rel="stylesheet" type="text/css"> -->
<link href="[var.out.html_res_root]/res/user.css" rel="stylesheet" type="text/css">
<link href="[var.out.html_res_root]/res/css/map.css" rel="stylesheet" type="text/css">
<link rel='stylesheet' type='text/css' href='[var.out.html_res2_root]/res/TileB.css?ver=[var.out.app_version]'>

<script src="[var.out.arena_res_root]/res/jquery.min.js?ver=[var.out.app_version]"></script>
<script>
window.arena = {};
</script>
<script src='[var.out.arena_res_root]/res/lang/cn.js?ver=[var.out.app_version]'></script>
<script>(function(){ "strict mode";
   if ( arena.lang ) {
      /** Tried to dynamically insert but always loaded after existing scripts, 
       * we need the error messages to load before them, so just load all languages first. */
      var lang = location.search.match( /[?&]lang=(\w+)($|&)/ );
      if ( lang ) {
         lang = lang[1];
      } else {
         lang = navigator.language || navigator.userLanguage;
      }
      if ( lang && lang.indexOf('zh-CN') > -1 ) {
        arena.lang = arena.lang.cn;
      }else if ( lang &&lang.match( /^zh(-.+)?$/ ) ) {
        arena.lang = arena.lang.zh;
      } else {
        arena.lang = arena.lang.en;
      }
      // document.getElementById('hint').innerHTML = arena.lang.ui.initial;
   }
})()</script>
<script src='[var.out.arena_res_root]/res/kis.js?ver=[var.out.app_version]'></script>
<script src='[var.out.arena_res_root]/res/model.js?ver=[var.out.app_version]'></script>
<script src='[var.out.arena_res_root]/res/ui.js?ver=[var.out.app_version]'></script>
<script src='[var.out.arena_res_root]/res/tools.js?ver=[var.out.app_version]'></script>
<script src='[var.out.arena_res_root]/res/commands.js?ver=[var.out.app_version]'></script>
<script src='[var.out.arena_res_root]/res/io.js?ver=[var.out.app_version]'></script>
<script src='[var.out.arena_res_root]/res/kis_panel.js?ver=[var.out.app_version]'></script>


</head>
<body>

<script type="text/javascript">
var result="";
var map_w="[var.out.map_w]";
var map_h="[var.out.map_h]";

// $(document).ready(function(){
	
// });

window.map2arena = {};

map2arena.reset = function() {
  arena.tools.setTool(arena.tools.Brush);
  var w = (arena.map.width <= 0) ? 36 : arena.map.width;
  var h = (arena.map.height <= 0) ? 24 : arena.map.height;
  // Clear data
  arena.map.layers = [];
  arena.map.layer = null;
  //for (var l = map.layers.length-1; l >= 0; l--)
  //  map.layers[l].cells = [];
  map2arena.maprecreate(w, h);  // arena.map.recreate(w, h);
  for ( var i in arena.lang.layers ) {
    arena.map.addLayer(new arena.Layer( arena.lang.layers[i] ));
  }
  arena.ui.updateLayers();
  arena.ui.setText('');
  arena.ui.setForeground(arena.map.background_fill.foreground);
  arena.ui.setBackground(arena.map.background_fill.background);
  arena.commands.resetUndo();
  arena.tools.Crop.sx = null; // arena.tools.Crop.sy = arena.tools.Crop.ex = arena.tools.Crop.ey = null;
  arena.map.setModified( false );
};

map2arena.maprecreate =function(width, height) {
    var map = arena.map;
    //$('#map')[0]        //fix me
    var table = map.table;
    var tbody = document.getElementsByTagName('tbody')[0];

    // Clear map
    map.cells = [];
    // for (var y = tbody.getElementsByTagName('tr').length-1; y >= 0; y--)
    //    table.deleteRow(y);

    // Set new stats
    map.width = width;
    map.height = height;
    map.marked = [];
    map.masked = [];

    // Create cells and borders above cells
    for (var y = 0; y < height; y++) {
      var r = arena.map.createCellRow(y, y > 0 ? map.cells[y-1] : null);
      tbody.appendChild(r[0]);
      map.cells[y] = r[1];
    }
    arena.ui.setStatus(arena.lang.command.name_CreateMap + ' '+width+'x'+height);
    map.repaint();

    map.setModified( false );
    map.lastSaveTime = new Date();
};

function export_arean_json(evt){
    arena.map.width = +map_w;
    arena.map.height = +map_h;
    map2arena.reset();  // arena.reset();

    evt = evt||{};
    evt.ctrlKey = false;
    evt.metaKey = false;

    var result = '', cells = arena.map.cells;

    for (var y = 0; y <= arena.map.height; y++) { 
        var row = cells[y];
        for (var x = 0; x <= arena.map.width; x++) {
            var map_div = $("#div_"+x+"_"+y);
            if(map_div && map_div[0] )
              if( map_div[0].style && map_div[0].style.background){
                //skip
            }else{
                arena.event.glyphOnClick(evt,'墙');
                arena.tools.Text.draw(evt,x,y);
            }
        }
    };

    var ret = arena.io.exportToJSON(arena.map, null);
    // alert( ret );
    $('#rndmap').hide();
    arena.ui.copyText(ret);

}

function op2(){
    arena.ui.hideDialog("text");
    $('#rndmap').show();
}
</script>
<p>
<a href="?ks=1[var.out.reload_cgi; htmlconv=no]" target="_reloadrndmap">reload link</a>  
&nbsp;<a href="?c=show&a=alllink" target="_allmap">all link</a>  
&nbsp;<a href="javascript:export_arean_json(event);" target="_allmap">Export json for Sheep's Arena</a>  
</p>

<div style="margin:20px auto;" class="mg" id="rndmap">
[var.out.map_html; htmlconv=no]
</div>
<!--
[var.out.time_log; htmlconv=no]
-->
<hr/>
<table id='map' style="display:none;"><tbody><tr><td style='width: auto; max-width: none; font-size:x-large; padding:2em 4em'>Please wait a few seconds.</td><tr></tbody></table>
<hr/>
<div id='layer' style="display:none;">
</div>
<script src='[var.out.arena_res_root]/res/rawinflate.js'></script>
<script src='[var.out.arena_res_root]/res/rawdeflate.js'></script>
<script src='[var.out.arena_res_root]/res/base64.js'></script>
<script>"strict mode";
  if ( arena && arena.io ) arena.io.autoLoad();
</script>
<div id='dialog_export' onkeydown='arena.event.dialogKeyDown(event)'>
</div>
<div id='dialog_text' onkeydown='arena.event.dialogKeyDown(event)'>
  <h2 id='titleData'>Data</h2>
  <p id='text_instruction'>arena.lang.io.CopyInstruction</p>
  <textarea id='text_data' rows='10' cols='40' onkeyup='arena.event.dlgTextChanged(event, this.value)'>
  </textarea>
  <br><br>
  <input class='cancel' type='button' value='Cancel' onclick='op2()'>
</div>
</body>
</html>